/**
 * 
 */
package userController;


import java.sql.SQLException;
import java.io.IOException;

import rentReturnController.RentController;
import rentReturnController.ReportController;
import reservationController.ReservationController;
import rentReturnController.ReturnController;
import vehicleController.ViewVehicleController;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * @author Aakash Singh
 *
 */
public class ClerkController {

	@FXML
	private Label userName;

	@FXML
	private Stage clerkStage;

	@FXML
	public String customerPhNo;

	@FXML
	private StackPane clerkStackPane;
	
	@FXML
	private DatePicker reservation_pickup_date;
	@FXML
	private DatePicker return_date;
	
	@FXML
	private ComboBox reservation_vehicle_class;
	@FXML
	private ComboBox reservation_driver_age;
	@FXML
	private ComboBox reservation_vehicle_capacity;
	@FXML
	private ComboBox reservation_vehicle_equipments;
	@FXML
	private ComboBox reservation_pickup_time;
	@FXML
	private ComboBox reservation_return_time;
	@FXML
	private ComboBox reservation_vehicle_type;
	@FXML
	private Button reservation_price_quote;
	

	/**
	 * @param clerkStackPane the clerkStackPane to set
	 */
	public void setClerkStackPane(Node node) {
		clerkStackPane.getChildren().setAll(node);
	}
	public void setName(String name){
		//userName = new Label(name);
		userName.setText(name);
	}

	public void SetStage(Stage Stage){
		this.clerkStage=Stage;
	}

	/**
	 * Invoke reservationcontroller.makeReservation
	 * @param event
	 */
	@FXML
	public void doReservation(ActionEvent event){

		ReservationController rcController = new ReservationController();
		rcController.page=-1;
		rcController.makeReservation();
	}

	/**
	 * Invoke reservationcontroller.cancelreservation
	 * @param event
	 */
	@FXML
	public void cancelReservation(ActionEvent event){
		System.out.println("Cancel reservation");
		ReservationController rc = new ReservationController();
		rc.cancelReservation();

	}

	/**
	 * Invoke rentcontroller.dorent
	 * @param event
	 */
	@FXML
	public void rentVehicle(ActionEvent event){
		RentController rentControl = new RentController();
		rentControl.doRent();
	}


	@FXML
	public void showOverDueVehicles(ActionEvent event)
	{
		RentController.setSceneNumber(7);
		Navigator.loadStackPane(Navigator.OverDUEVEHICLES);
	}
	/**
	 * Invoke Returncontroller.doReturn
	 * @param event
	 */
	@FXML
	public void returnVehicle(ActionEvent event){
		ReturnController returnControl = new ReturnController();
		returnControl.doReturn();
	}

	/**
	 * Invoke Usercontroller.viewVehicleStatus method
	 * @param event
	 */
	@FXML
	public void viewVehicleStatus(ActionEvent event){
		Navigator.loadStackPane(Navigator.VEHICLE_STATUS);
	}

	@FXML
	public void viewAllVehicles(ActionEvent event){
		ReportController.page=1;
		Navigator.loadStackPane(Navigator.OVERALLVEHICLELIST);
	}
	@FXML
	public void editCustomerProfile(ActionEvent event) throws SQLException{
		UserController.page = 5;
		Navigator.loadStackPane(Navigator.EDITCUSTOMERPROFILEFXML);

	}

	/**
	 * Invoke Usercontroller.viewSaleList method
	 * @param event
	 */
	@FXML
	public void viewSaleList(ActionEvent event){
		ViewVehicleController viewVehicleControl =  new ViewVehicleController();
		viewVehicleControl.viewSaleList();
	}

	/**
	 * UserController.editProfile() method
	 * @param event
	 */
	@FXML
	public void editProfile(ActionEvent event){
		UserController clerkobjedit = new UserController();
		clerkobjedit.editProfile(Navigator.getPhoneNumber());
	}

	/**
	 * load usercontroller.changePassword method
	 * @param event
	 */
	@FXML
	public void changePassword(ActionEvent event){
		UserController user = new UserController();
		user.changePassword();

	}
	
	@FXML
	public void home(ActionEvent event){
		Navigator.loadStackPane(Navigator.CLERK_HOME);
	}
	
	/**
	 * Handles Clerk Logout function
	 * @param event
	 * @throws IOException
	 */
	@FXML
	public void logout(ActionEvent event) throws IOException{
		Navigator.setClerk(null);
		Navigator.setPhoneNumber(null);
		FXMLLoader myLoader = new  FXMLLoader(getClass().getResource("/userManagementUI/LoginPage.fxml"));
		Stage MainStage = new Stage();
		Pane MainPagePane = (Pane)myLoader.load();
		LoginController controller = (LoginController) myLoader.getController();
		controller.SetStage(MainStage);
		// stage.setTitle("Login");
		Scene myScene = new Scene(MainPagePane);        
		MainStage.setScene(myScene);
		MainStage.setTitle("SUPERRENT");
		MainStage.setResizable(false);
		MainStage.setWidth(605);
		MainStage.setHeight(445);
		MainStage.show();
		clerkStage.close();
	}
}
